<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function test1() {
      var x = Math.random();
      var y = Math.random();
      console.log('x的值为:' + x, 'y的值为' + y)
      console.log('较大的值为：' + x > y ? x : y);
    }
    function test2() {
      var today = new Date();
      var year = today.getFullYear();
      if ((year / 4 == 0 && year % 100 != 0) || year % 400 == 0) {
        return console.log(true);
      } else {
        return console.log(false);
      }
    }
    function test4() {
      //promt弹窗显示
      var num = prompt('请输入0-6之间的数字')
      num = parseInt(num);
      switch (num) {
        case 0:
          //弹窗输出
          alert('星期日');
        case 1:
          alert('星期一');
        case 2:
          alert('星期二');
        case 3:
          alert('星期三');
        case 4:
          alert('星期四');
        case 5:
          alert('星期五');
        case 6:
          alert('星期六');
        default:
          alert('那咋不对了呢');
      }
    }
    function test7() {
      for (var i = 1; i < 5; i++) {
        for (var j = 1; j <= i; j++) {
          //docunment.write():打印在页面上
          document.write(j + ' ');
        }
        //换行:<br>
        document.write('<br>')
      }
    }
    function test8() {
      for (var i = 1; i <= 5; i++) {
        for (var j = 1; j <= (5 - i); j++) {
          document.write('&nbsp;');
        }
        for (var k = 1; k <= i; k++) {
          //&nbsp空格
          document.write('*&nbsp;');
        }
        document.write('<br>')
      }
    }
    function Test1() {
      var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
      arr.sort(function (a, b) {
        return 0.5 - Math.random()
      });
      document.write(arr);
    }
    function Test2(num) {
      var arr = num.toString().split('.');
      var arr1 = arr[0].split('').reverse();
      var res = [];
      for (var i = 0; i < arr1.length; i++) {
        if (i % 3 == 0 && i != 0) {
          res.push(',');
        }
        res.push(arr1[i]);
      }
      return res.reverse().join('') + '.' + arr[1];
    }
    //console.log(Test2(12000000.11))
    function Test3(str) {
      var str1 = '';
      var str2 = '';
      for (var i = str.length; i >= 0; i--) {
        str1 += str[i];
      }
      return str1 == str;
    }
    //Test
    var Test4 = [1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 8, 88, 9]
    Array.prototype.unique = function () {
      var res = [];
      var o = {};
      var length = this.length;
      for (var i = 0; i < length; i++) {
        var v = this[i];
        if (!o[v]) {
          o[v] = 1;
          res.push(v);
        }
      }
      return res;
    }
    //console.log(Test4.unique());
    function Test5() {
      var obj = {
        name: 'guanxu',
        age: 22,
        son: {
          name: 'lisi',
          age: 20.
        }
      };
      for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
          console.log(obj[i]);
        }
      }
    }
    function Test6(str) {
      for (var i = 0; i < str.length; i++) {
        if (str[i] >= 0 || str[i] <= 9) {
          return true;
        }
      }
      return false;
    }
    //console.log(Test6('gsdjhdahj3242ds'))
    function Test7(a, b) {
      var stra = a.toString();
      var strb = b.toString();
      var length1 = (stra.indexOf('.') == -1) ? 0 : (stra.length - stra.indexOf('.') - 1);
      var length2 = (strb.indexOf('.') == -1) ? 0 : (strb.length - strb.indexOf('.') - 1);
      var length = Math.max(length1, length2);
      var result = parseFloat(a * b).toFixed(length);
      return result;
    }
    //document.write(Test7(1, 0.00003));
    function Test8(arr, item) {
      var newArr = [];
      newArr = arr.slice(0);
      var index = newArr.indexOf(item);
      while (index != -1) {
        newArr.split(index, 1);
        index = newArr.indexOf(item);
      }
      return newArr;
    }
    function Test9(num) {
      var str = num.toString();
      var length = str.length;
      var a = 8 - length;
      for (var i = 0; i < a; i++) {
        str = '0' + str;
      }
      return str;
    }
    //console.log(Test9(66));
    function Test10() {

    }
    var arr = [1, 2, 34, 4, 46, 25, 45];
    function Test11(arr) {
      arr.sort(function (a, b) {
        return a - b;
      });
    }
    function Test12(str) {//str8位
      var year = Math.floor(str / 10000);
      var month = Math.floor(str / 100) % 100;
      var day = Math.floor(str % 100);
      document.write(year + '年' + month + '月' + day + '日');
    }
    //Test12(20231024);
    function Test13() {
      //1为石头，2为剪刀，3为布
      var a = Math.floor(Math.random() * 3) + 1;
      var b = prompt('请输入1-3之间的整数,1为石头,2为剪刀,3为布');
      var result = null;
      switch (b) {
        case '1':
          if (a == 1) {
            result = '平局';
          } else if (a == 2) {
            result = '你赢了';
          } else if (a == 3) {
            result = '你输了';
          }
        case '2':
          if (a == 1) {
            result = '你输了';
          } else if (a == 2) {
            result = '平局';
          } else if (a == 3) {
            result = '你赢了';
          }
        case '3':
          if (a == 1) {
            result = '你赢了';
          } else if (a == 2) {
            result = '你输了';
          } else if (a == 3) {
            result = '平局';
          }
          break;
      }
      document.write(result + '<br>');
      document.write('电脑的选择是：' + a + '<br>');
      document.write('你的选择是:' + b);
    }
    //Test13();
    function Test14(min, max) {
      if (max < min) {
        var tmp = max;
        max = min;
        min = tmp;
      }
      var random = min + Math.floor(Math.random() * (max - min + 1));
      return random;
    }
    //document.write(Test14(2, 34));
    var sum = 0;
    function Test15() {
      for (var i = 0; i < 64; i++) {
        sum += Math.pow(2, i);
      }
      sum *= 0.00001;
      document.write(sum);
    }
    //Test15();
    function Test16() {
      for (var i = 1; i <= 100; i++) {
        if (i % 7 != 0) {
          var a = i + '';
          if (a.indexOf("7") == -1) {
            document.write(a + '<br>');
          }
        }
      }
    }
    //Test16();
    function Test17(n) {
      var sum = 1;
      if (n == 0 || n == 1) {
        return 1;
      }
      if (n % 2 != 0) {
        for (var i = 0; i <= (n - 1) / 2; i++) {
          sum += 1 / (2 * i + 1);
        }
        return sum;
      } else {
        for (var i = 0; i <= n / 2; i++) {
          sum += 1 / (2 * i);
        }
        return sum;
      }
    }
    //var sum = Test17(5)
    //console.log(sum);
    function sequene(n) {
      var str = '';
      for (var i = 1; i <= n; i++) {
        str += i;
      }
      return str * 1;
    }
    function Test18(m, n) {
      var count = 0;
      for (var a = m; a <= n; a++) {
        var seq = sequene(a);
        if (seq % 3 == 0) {
          count++;
        }
      }
      return count;
    }
    function sequene2(n) {
      var strl = "";
      var strr = "";
      for (var i = 1; i <= n; i++) {
        strl += i;
      }
      for (var j = n - 1; j >= 1; j--) {
        strr += j;
      }
      return (strl + strr) * 1;
    }
    var data = [{
      id: 1,
      name: '家电',
      goods: [{
        id: 11,
        name: '冰箱',
        goods: [{
          id: 111,
          name: '海尔',
        }, {
          id: 112,
          name: '格力',
        }]
      }, {
        id: 12,
        name: '洗衣机',
      }]

    }, {
      id: 2,
      name: '服饰'
    }];
    function Test19(data, id) {
      var res = {};
      data.forEach(function (item) {
        if (item.id == id) {
          res = item;
        } else if (item.goods && item.goods.length > 0) {
          res = Test19(item.goods, id)
        }
      })
      return res;
    }
    //document.write(Test19(data, 112));
    function Test20(n) {
      var sum = 0;
      for (var k = 1; k <= n; k++) {
        sum += sequene2(k);
      }
      return sum;
    }
    //console.log(Test20(3));
    function Test21(name) {
      if (name.charAt(0) == '-') {
        name = name.slice(1);
      }
      var arr = name.split('-');
      var str = '';
      for (var a = 0; a < arr.length; a++) {
        if (a == 0) {
          str += arr[a];
        } else {
          for (var j = 0; j < arr[a].length; j++) {
            if (j == 0) {
              str += arr[a].charAt(0).toUpperCase();
            } else {
              str += arr[a].charAt(j);
            }
          }
        }
      }
      return str;
    }
    //console.log(Test21('hello-my-world'));
    var objArr = [{ a: 1, b: 2 }, { a: 5 }, { a: 7, b: 8, d: 9 }];
    function Test22(obj1, obj2) {
      var a = function (ob) {
        s = 0;
        for (var i in ob) {
          s++;
        }
        return s;
      }
      return a(obj1) - a(obj2);
    }
    objArr.sort(Test22);
    console.log(objArr);

    var numObj = new Number(5);
    var num = numObj.valueOf();
    Number.prototype.plus = function (num) {
      var thisNum = this.valueOf();
      return thisNum + num;
    };
    Number.prototype.minus = function (num) {
      var thisNum = this.valueOf();
      return thisNum - num;
    };
    Number.prototype.mult = function (num) {
      var thisNum = this.valueOf();
      return thisNum * num;
    };
    Number.prototype.div = function (num) {
      var thisNum = this.valueOf();
      return thisNum / num;
    };
    // var a = (5).plus(3).minus(6);
    // var b = (10).div(5).plus(4);
    // console.log('a=' + a);
    // console.log('b=' + b);
    function Test24(a1) {
      return (function (a2) {
        return (function (a3) {
          return a1 + a2 + a3;
        });
      });
    };
    // var a = Test24(2)(3)(4);
    // console.log('a=' + a);
    function Test25(str, len, pad) {
      var left = Math.floor((len - str.length) / 2);
      var right = len - left - str.length;
      if (len > str.length + pad.length * 2) {
        var length = Math.ceil((len - str.length) / 2);
        var repeat = Math.ceil(length / pad.length);
        while (repeat--) {
          pad += pad;
        }
        return pad.substr(0, left) + str + pad.substr(0, right);
      }
    }
    function Test26() {
      var str = '';
      for (var i = 1; i <= 4; i++) {
        for (var j = 1; j <= 4; j++) {
          for (var k = 1; k <= 4; k++) {
            if (i != j && j != k && i != k) {
              str += i;
              str += j;
              str += k;
              document.write(str + '<br>');
              str = '';
            }
          }
        }
      }
    }
    //Test26();

    function Test27() {
      var a = prompt('请输入当月利润: (单位:万元)');
      var i = parseInt(a);
      var money = 0;
      if (i <= 10) {
        money = i * 0.1;
      } else if (i > 10 && i <= 20) {
        money = 10 * 0.1 + (i - 10) * 0.075;
      } else if (i <= 40 && i > 20) {
        money = 10 * 0.1 + 10 * 0.075 + (i - 20) * 0.05;
      } else if (i <= 60 && i > 40) {
        money = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (i - 40) * 0.3;
      } else if (i <= 100 && i > 60) {
        money = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 40 * 0.03 + (i - 60) * 0.015;
      } else {
        money = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 40 * 0.03 + 60 * 0.015 + (i - 100) * 0.01;
      }
      return money;
    }
    //console.log(Test27());
    function Test28() {
      var a = prompt('请输入一个字符串,我会删除其中的aeiou');
      var str = a;
      var str1 = '';
      for (var i = 0; i < str.length; i++) {
        if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u') {
          str1 += str[i];
        }
      }

      document.write(str1);
    }
    //Test28();
    function Test29() {
      for (var i = 100; i <= 999; i++) {
        var a = Math.floor(i / 100);
        var b = Math.floor(i / 10 % 10);
        var c = Math.floor(i % 10);
        if (i == a * a * a + b * b * b + c * c * c) {
          document.write(i + '<br>');
        }
      }
    }
    //Test29();
    function Test30() {
      var f = 1;
      for (var i = 1; i <= 9; i++) {
        f = (f + 1) * 2;
      }
      return f;
    }
    //document.write('第一天猴子吃了' + Test30() + '个桃子');
    function Test31() {
      var str = prompt('请输入一串字母数字空格和其他字符的集合：')
      var num = 0;
      var nul = 0;
      var ano = 0;
      var x = 0;
      for (var i = 0; i < str.length; i++) {
        if ((str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') || (str.charAt(i) >= 'a' && str.charAt(i) <= 'z')) {
          x++;
        } else if (str.charAt(i) == '') {
          nul++;
        } else if ((str.charAt(i) <= 9) || str.charAt(i) >= 0) {
          num++;
        } else {
          ano++;
        };
      };
      document.write('英文字母有' + x + '个' + '<br>');
      document.write('数字有' + num + '个' + '<br>');
      document.write('空格有' + nul + '个' + '<br>');
      document.write('其他字符有' + ano + '个');
    }
    //Test31();
    var arr = ['a', 'b', 'c'];
    function Test32() {
      for (var x = 0; x < 3; x++) {
        for (var y = 0; y < 3; y++) {
          for (var z = 0; z < 3; z++) {
            if ((x != 0 && x != 2) && (z != 2)) {
              document.write('x VS ' + arr[x]);
              document.write('<br>');
              document.write('y VS ' + arr[y]);
              document.write('<br>');
              document.write('z VS ' + arr[z]);
              document.write('<br>');
              document.write('<br>');
            };
          }
        }
      }
    }
    //Test32();
  </script>
</body>

</html>